DEFINITION MODULE Terminal; (* Franz Kronseder / ETHZ / 19.06.85 /15.8.85 *)

 (* Standard Screen Output and Keyboard Input for Modula-2 programs *)                           *)

 EXPORT QUALIFIED Write, WriteString, WriteLn, Read, ReadString,
                  BusyRead, ReadAgain, KeyPress, GotoXY, ClearTerminal;

 PROCEDURE Write (ch: CHAR);
   (* Write a character. Interprets CR,FF,BS,DEL,BEL,36C. CR-only is 35C!  *)

 PROCEDURE WriteString (VAR s: ARRAY OF CHAR);
    (* write string in "s". A NUL-character signals end of string. *)

 PROCEDURE WriteLn;

 PROCEDURE Read (VAR ch: CHAR);
    (* reads one character from keyboard. The character is not echoed! *)
    (* returns the character code of the of the key pressed            *)

 PROCEDURE ReadString (VAR s: ARRAY OF CHAR);
    (* read a string; does echo, interprets BS,CAN, terminates with CR or ESC*)

 PROCEDURE BusyRead (VAR ch: CHAR);
    (* reads a character without waiting; returns 0C if there was no character *)

 PROCEDURE ReadAgain;
    (* put the last character read back in the input buffer. *)
    (* usefull, if you want to do your own line editing.     *)

 PROCEDURE KeyPress(): BOOLEAN;
  (* returns TRUE if keyboard buffer not empty *)

 PROCEDURE GotoXY(x,y: INTEGER);
  (* sets cursor to screen-position (x=horizontal,y=vertical) in characters.
     for proportional fonts, measure is in (always non-proportional) digits   *)

 PROCEDURE ClearTerminal;
   (* sets the terminal bitmap to background colour and positions the cursor on
      the first line *)


 (* Note for the Macintosh: Read/BusyRead also simulate ctrl-X characters, as
    follows:
    command-A .. command-Z :     01C .. 32C    (ctrl-alpha)
    command-a .. command-z :     01C .. 32C    (ctrl-alpha)
    command-[, -], -\, -^,-_:    33C .. 37C    (ctrl-special)
    command-3 .. command-7 :     33C .. 37C.   (ctrl-others. ctrl-3=ESC)
 *)

 END Terminal.
